<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var countCollisions = function (num) {
      //去掉开始的'L'
      while (num[0] == 'L') {
        num = num.slice(1)
      }
      //去掉结尾的'R'
      while (num[num.length - 1] == 'R') {
        num = num.slice(0, num.length - 1)
      }
      //去掉'S'
      num = num.replaceAll('S', '')
      return num.length
    };
    console.log(countCollisions(num = "RLRSLL"))
  </script>
</body>

</html>